package com.nf.health.app.healthbank.adapter;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.customview.CircleImageView;
import com.nf.health.app.inquiry.bean.DoctorDetailBean;
import com.nf.health.app.inquiry.docdetail.DocDetailActivity;
import com.nf.health.app.utils.ActivityUtils;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by hepann on 2016/10/9.
 * The only genius that is worth anything is the genius for hard work
 *
 * @author hepann
 * @Description 健康银行底部医生
 * @email he_pann@163.com
 */
public class BottomDoctorListAdapter extends RecyclerView.Adapter<BottomDoctorListAdapter.ViewHolder> {
    private List<DoctorDetailBean> mDoctorList;
    private Context ctx;

    public BottomDoctorListAdapter(List<DoctorDetailBean> mDoctorList, Context ctx) {
        this.mDoctorList = mDoctorList;
        this.ctx = ctx;
    }

    @Override
    public BottomDoctorListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(ctx, R.layout.item_bottom_doctor_list, null);//这里传parent报错
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(BottomDoctorListAdapter.ViewHolder holder, int position) {
        final DoctorDetailBean bean = mDoctorList.get(position);
        ImageLoaderUtils.getinstance(ctx).getImage(holder.ivDoctorHead, bean.getDoctorhimg(), R.drawable.default_image);
        holder.tvDoctorDepartment.setText(bean.getDepartment());
        holder.tvDoctorName.setText(bean.getDoctorname());
        holder.llContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle docDetailBundle = new Bundle();
                docDetailBundle.putString(DocDetailActivity.DOCTORID, bean.getDoctorid());
                ActivityUtils.showActivity(ctx, DocDetailActivity.class, docDetailBundle);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDoctorList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.ll_content)
        LinearLayout llContent;
        @Bind(R.id.iv_doctor_head)
        CircleImageView ivDoctorHead;
        @Bind(R.id.tv_doctor_name)
        TextView tvDoctorName;
        @Bind(R.id.tv_doctor_department)
        TextView tvDoctorDepartment;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
